package com.service;

import com.dao.Accountdao;
import com.domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("accountservice")
public class AccountserviceImpl implements Accountservice {
    @Autowired
    private Accountdao accountdao;
    @Override
    public Account findaccountbyid(Integer id) {
        return accountdao.findaccountbyid(id);
    }

    @Override
    public List<Account> tran(String name1, String name2,
                              float money) {
        Account user1=accountdao.findaccountbyname(name1);
        Account user2=accountdao.findaccountbyname(name2);
        user1.setMoney(user1.getMoney()-money);
        user2.setMoney(user2.getMoney()+money);
        accountdao.update(user1);
        accountdao.update(user2);
        return accountdao.findall();
    }
}
